package ljl.alg.jianzhioffer.round3.medium;

public class _4_findNumberIn2DArray {

    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix.length == 0) return false;
        int m = matrix.length;
        int n = matrix[0].length;
        int r = 0, col = n - 1;
        while (r < m && col > -1) {
            int val = matrix[r][col];
            if (val == target)
                return true;
            if (val < target)
                r++;
            else
                col--;
        }
        return false;
    }
}
